package com.funo.logic.generate.wrapper;

import com.funo.logic.constant.SymbolConstants;
import org.apache.commons.lang.StringUtils;

/**
 * 注解类引用
 * @since 2024年7月23日16:24:09
 * @author cms
 */
public class AnnotationClassWrapper extends ClassWrapper {

    private String value;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public static AnnotationClassWrapper of(String name, String value) {
        AnnotationClassWrapper annotationClassWrapper = new AnnotationClassWrapper();
        annotationClassWrapper.setFullName(name);
        annotationClassWrapper.setName(getClassShortRawName(name));
        annotationClassWrapper.setShortName(getClassShortName(name));
        annotationClassWrapper.setShortRawName(getClassShortRawName(name));
        annotationClassWrapper.setPackageName(getClassPackage(name));
        annotationClassWrapper.setParameterizedType(getClassParameterizedType(name));
        if (StringUtils.isNotBlank(value)) {
            annotationClassWrapper.setValue(value);
        }
        return annotationClassWrapper;
    }

    public static AnnotationClassWrapper of(Class clazz, String value) {
        return of(clazz.getName(), value);
    }

    public String generateCode() {
        StringBuffer sb = new StringBuffer();
        if (StringUtils.isBlank(getValue())) {
            sb.append("@").append(getName());
        } else {
            sb.append("@").append(getName()).append(SymbolConstants.OPEN_PAREN)
                    .append(SymbolConstants.QUOTATION).append(getValue()).append(SymbolConstants.QUOTATION)
                    .append(SymbolConstants.CLOSE_PAREN);
        }
        return sb.toString();
    }
}
